package com.mingqijia.gassafety.shared.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 性别枚举
 * @author Damon S.
 */
@Getter
@RequiredArgsConstructor
public enum GenderEnum {
    /** 0未知，1男，2女 */
    NA(0), MALE(1), FEMALE(2);

    private final int code;

    public static GenderEnum parse(int code) {
        List<GenderEnum> filtered = Arrays.stream(GenderEnum.values())
                .filter(item -> Objects.equals(item.getCode(), code))
                .collect(Collectors.toList());
        return CollectionUtils.isEmpty(filtered) ? NA : filtered.get(0);
    }
}